<%
Option Explicit
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1  
Response.cachecontrol = "no-cache"  

Dim ImgFileContent,BitNum
If Request("t")="" Then BitNum=4 Else BitNum=5
ImgFileContent=GenerateCheckCode(BitNum)
Response.ContentType = "image/BMP"
Response.BinaryWrite ImgFileContent

function GenerateCheckCode(BitNum)
	On Error Resume Next
	Dim zNum,rNum,i,j,CodeLetter,CodeList
	Dim AdoM,AdoN,BitWidth,BitHeight,BitBytes
	BitWidth=10:BitHeight=15
	BitBytes=(BitWidth*3+2)*BitHeight   
    CodeLetter = "0123456789abcdefghijklmnopqrstuvwxyz"
	Randomize Timer
	Dim zimg(6)
	For i = 0 To BitNum
        rNum = Int(34 * Rnd)+2
		If rNum=18 Or rNum=21 Or rNum=24 Then 
			i=i-1
		Else 
			zimg(i) = rNum
			CodeList = CodeList & Mid(CodeLetter,rNum+1,1)
		End if
    Next
	Session("ValidateCode") = CodeList
	Dim Pos
	Set AdoM=Server.CreateObject("Adodb.Stream")
	AdoM.Mode=3
	AdoM.Type=1
	AdoM.Open
	Set AdoN=Server.CreateObject("Adodb.Stream")
	AdoN.Mode=3
	AdoN.Type=1
	AdoN.Open
	AdoM.LoadFromFile(Server.mappath("../images/body.Fix"))
	AdoN.write AdoM.read(BitBytes*(BitNum+1))

	For i=0 To BitNum
		AdoM.Position=(35-zimg(i))*BitBytes
		AdoN.Position=i*BitBytes
		AdoN.write AdoM.read(BitBytes)
	Next	
	AdoM.LoadFromFile(Server.mappath("../images/head"&BitNum&".fix"))
	Pos=LenB(AdoM.read())
	AdoM.Position=Pos
	Dim RowVacancy,RowBytes
	RowBytes=3*BitWidth*(BitNum+1) 
	RowVacancy=RowBytes Mod 4
	For i=0 To 14
		For j=0 To BitNum
			AdoN.Position=i*(3*BitWidth+2)+j*BitBytes
			AdoM.Position=Pos+3*BitWidth*j+i*(RowBytes+RowVacancy)
			AdoM.write AdoN.read(3*BitWidth)
		Next
		If RowVacancy<>0 Then 
			AdoM.Position=Pos+RowBytes+i*(RowBytes+RowVacancy)
			AdoM.Write AdoN.read(RowVacancy)	
		End If
	Next
	AdoM.Position=0
	GenerateCheckCode=AdoM.read()
	AdoM.Close:set AdoM=nothing
	AdoN.Close:set AdoN=nothing
End function
%>